﻿using System.Data.Entity.ModelConfiguration;
using ZSoftInstagram.Domain.Board;

namespace ZSoftInstagram.DataAccess.Config
{
    public class ImagePinConfig: EntityTypeConfiguration<ImagePin>
    {
        public ImagePinConfig()
        {
            this.HasKey(p => p.Id);

            this.HasMany(p => p.Tags)
                    .WithMany(t => t.Pins)
                        .Map(t => t.MapLeftKey("PinId").MapRightKey("TagId"));

            this.HasMany(p => p.Comments)
                .WithRequired(c => c.ImagePin)
                .HasForeignKey(c => c.ImagePinId);

            this.HasRequired(p => p.Address)
                .WithOptional(a => a.ImagePin);

            this.HasMany(img => img.Likes)
                .WithRequired(l => l.ImagePin)
                .HasForeignKey(l => l.ImagePinId);
        }
    }
}
